<?php
/**
 * Created by PhpStorm.
 * User: kb130
 * Date: 2017/8/21
 * Time: 14:10
 */

namespace util\validate\rules;

/**
 * 验证值是否是一个合法的url地址
 * Class Url
 * @package validate\rules
 */
class Url extends BaseRule
{
    public function verify()
    {
        $isOk = checkdnsrr($this->value);

        if ($isOk) {
            return true;
        }

        $match = '/^(https?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/';

        return preg_match($match, $this->value);
    }
}